/*
 *  Arrow
 *
 *  Created by David Giovannini on 1/5/07.
 *  Copyright 2007 Software by Jove. All rights reserved.
 *
 */
 
#ifndef MockMessage_h
#define MockMessage_h

#include "SBJ/Arrow/Message.h"
#include "SBJ/Interfaces/IRemora.h"

void test_sleep( double secs );

class MockSubscriber : public SBJ::Host
{
public:
  MockSubscriber( void );
  virtual ~MockSubscriber( void );
};

class MockMessage : public SBJ::Arrow::Message
{
public:
	typedef MockSubscriber Subscriber;

	static const char* hit_none;
	static const char* hit_execute;
	static const char* hit_execute_HasTest;
	static const char* hit_dispatch_ToNULL;
	static const char* hit_dispatch_ToTest;
	static const char* hit_dispatch_ToUnknown;

	struct Accume
	{
		Accume() : upper( 0 ), lower( 0 ), acquired( 0 ) {}
		int upper;
		int lower;
		int acquired;
	};

	MockMessage( volatile const char*& hit, 
				const Topic& topic,
				Priority priority = highest_priority,
				const Accume& accume = Accume() );

	MockMessage( volatile const char*& hit,
				const Topic& topic, 
				Priority priority,
				Subscriber* test, 
				const Accume& accume = Accume() );

	MockMessage( MockMessage& rhs );

	virtual ~MockMessage( void );
	
	virtual size_t getThreadedThreshold( void ) const { return m_threadThreshold; }
	
	virtual bool doesBlockOnDispatch( void ) const { return m_blocks; }
	
	bool doesConsume( const MockMessage& rhs ) const;
	
	void consume( MockMessage& rhs );

	virtual void execute( void );
	
	virtual bool beginInvocations( size_t count );
	
	void invoke( Subscriber* );
	
	virtual void endInvocations( void );

	size_t m_threadThreshold;
	bool m_blocks;

private:
	volatile const char*& m_hit;
	Subscriber* m_test;
	Accume m_accume;
};

#endif
